package cn.zzu.Etrip.oneday.activity;

import android.app.Fragment;
import android.content.Intent;
import android.nfc.Tag;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.AdapterView;
import static android.widget.AdapterView.OnItemClickListener;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.example.administrator.etrip.R;

import cn.zzu.Etrip.twoday.activity.TwoDayPayActivity;


public class localFragment extends Fragment {
    ListView listView;
    private String[] descs2 = new String[]
            { "已售646 |4.7分", "已售646 |5.0分", "已售646 |4.8分", "已售646 |4.8分"};
    private double[] happy=new double[]{4.7,5.0,4.8,4.8};
    private String[] descs = new String[]
            {"[白马寺的美]嵩山少林寺、三皇寨一日（含武术表演 上门接）",
                    "[老君山的丽]嵩山少林寺、三皇寨一日（含武术表演 上门接）",
                    "[八达岭的风]嵩山少林寺、三皇寨一日（含武术表演 上门接）",
                    "[龙门石窟]嵩山少林寺、三皇寨一日（含武术表演 上门接）"};
    private String[] places=new String[]{"白马寺","老君山","八达岭","龙门石窟"};
    private String[] descs3= new String[]
            { "出发地：郑州", "出发地：郑州", "出发地：郑州", "出发地：郑州"};
    private String[] descs4= new String[]
            { "$65元起", "$320元起", "$100元起", "$150元起"};
    private int[] price={65,320,100,150};
    private int[] imageIds = new int[]
            { R.mipmap.oneday_bg_01,  R.mipmap.oneday_sm_mudancheng
                    , R.mipmap.text , R.drawable.textimage};
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
        View view=inflater.inflate(R.layout.fragment_oneday,container,false);

        return view;
    }
    public void onViewCreated(View view,Bundle savedInstanceState){
    super.onViewCreated(view,savedInstanceState);
        List<Map<String, Object>> listItems = new ArrayList<Map<String,Object>>();
        for (int i = 0; i < descs.length; i++) {
            Map<String, Object> listItem = new HashMap<String, Object>();
            listItem.put("header", imageIds[i]);
            listItem.put("descs", descs[i]);
            listItem.put("descs2", descs2[i]);
            listItem.put("descs3", descs3[i]);
            listItem.put("descs4", descs4[i]);
            listItems.add(listItem);
        }
            // 创建一个SimpleAdapter
            SimpleAdapter simpleAdapter = new SimpleAdapter(getActivity().getBaseContext(), listItems,
                    R.layout.locallistview,
                    new String[] { "header", "descs" , "descs2","descs3","descs4"},
                    new int[] { R.id.image1, R.id.text1 , R.id.text2,R.id.text3,R.id.text4});
            listView=view.findViewById(R.id.onedaylistview);
            listView.setAdapter(simpleAdapter);
            // 为ListView的列表项的单击事件绑定事件监听器
            listView.setOnItemClickListener(new OnItemClickListener()
            {
                // 第position项被单击时激发该方法
                @Override
                public void onItemClick(AdapterView<?> parent, View view,
                                        int position, long id)
                {
                    Intent intent=new Intent(getActivity().getBaseContext(),oneday_pay.class);
                    Bundle data=new Bundle();
                    data.putSerializable("photo",imageIds[position]);
                    String tag="position-----";
                    Log.d(tag,String.valueOf(position));
                    intent.putExtras(data);
                    intent.putExtra("价格",price[position]);
                    intent.putExtra("xxx",happy[position]);
                    intent.putExtra("目的地",places[position]);
                  startActivity(intent);
                }
            });

        }
    }

